package com.cskaoyan.bean;

import com.cskaoyan.support.ProxySupport;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//类似于动态代理
public class SongBrother3 extends LiuShifu{

    ProxySupport proxySupport = new ProxySupport();

    static Method method1;
    static Method method2;
    static {
        try {
            method1 = Class.forName("com.cskaoyan.bean.SongBrother3").getMethod("buyBreakfast");
            method2 = Class.forName("com.cskaoyan.bean.SongBrother3").getMethod("buyLunch");
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void buyBreakfast() {
        proxySupport.invoke(method1,new Object[0],this);
        //委托类要做的事情
        //super.buyBreakfast();
        //增强
        //enhance();
    }

    public void buyLunch() {
        proxySupport.invoke(method2,new Object[0],this);
    }



}
